package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.FieldType;
import ru.aslanov.schedule.client.ScheduleUser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 27, 2010 4:04:51 PM
 *
 * @author Sergey Aslanov
 */
public class GCalendarDS extends ChildDS {
    private static Map<String, DataSource> instances = new HashMap<String, DataSource>();

    public static DataSource getInstance(ScheduleUser scheduleUser) {
        DataSource dataSource = instances.get(scheduleUser.getScheduleKey());
        if (dataSource == null) {
            dataSource = new GCalendarDS(scheduleUser.getScheduleKey(), scheduleUser);
            instances.put(scheduleUser.getScheduleKey(), dataSource);
        }
        return dataSource;
    }


    private GCalendarDS(String parentId, InputLangProvider inputLangProvider) {
        super("GCalendar", parentId, "schedule", inputLangProvider);

        DataSourceField name = new DataSourceTextField("name");

        DataSourceField calendarId = new DataSourceField("calendarId", FieldType.TEXT, cnt.nameField());
        calendarId.setHidden(true);

        setFields(encodedKey, name, calendarId);        
    }
}
